import { message } from 'antd';
import axios, { AxiosResponse } from 'axios';
import { baseURL } from '../config/configFile';
import ArticleCate from '../types/ArticleCate';
import Response from '../types/Response';

// axios实例
const axiosInstance = axios.create({
    baseURL
})

//请求所有种类
export async function queryCategories(): Promise<Array<ArticleCate>> {
    try {
        const { data }: AxiosResponse<Response<Array<ArticleCate>>> = await axiosInstance.get('/queryCategories');
        if (!!data.success) {
            return data.data;
        } else {
            message.warning(data.message);
            return [];
        }
    }
    catch (e) {
        message.error('网络错误');
        return [];
    }
}